package com.seal.tsms.exam.controller;

import com.seal.tsms.base.controller.BaseController;
import com.seal.tsms.base.service.BaseService;
import com.seal.tsms.exam.entity.Exam;
import com.seal.tsms.exam.entity.Teacher;
import org.hibernate.criterion.DetachedCriteria;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.mvc.support.RedirectAttributesModelMap;

import java.util.List;

/**
 * Created by 爱猫的鱼 on 2016/6/6.
 */
@Controller
@RequestMapping("/exam")
public class ExamController extends BaseController<Exam,String> {
    @Override
    @Autowired
    @Qualifier("examServiceImpl")

    public void setSelfService(BaseService<Exam, String> selfService) {
        super.setSelfService(selfService);
    }
    @RequestMapping(value = "/save",method = RequestMethod.GET)
    public String create(){return "exam/exam/add";}
    @RequestMapping(value = "/save" ,method = RequestMethod.POST)
    @ResponseBody
    public String save(Exam exam, RedirectAttributesModelMap model){
        getSelfService().save(exam);
        model.addFlashAttribute("msg","成功保存一条数据");
        return "redirect:list.action";
    }
 public String list(Model model){
    List<Exam> exams= (List<Exam>) getSelfService().list(DetachedCriteria.forClass(Exam.class),null);
     model.addAttribute("exams",exams);
     return "exam/exam/list";
 }
}